#include<string.h>
#include<stdint.h>
#include<stdlib.h>
#include <icommon.h>
#include<mxu2.h>
#include<jzmxu128.h>
#include <stdio.h>
#include <sys/time.h>
//#include <imp/imp_log.h>
#ifdef DMALLOC
#include <imp/dmalloc.h>
#endif
static void c_resize_simd_nv12_up_h_720_960p_onlynear(uint8_t* src, uint8_t* dst, int src_w, int src_h, int dst_w, int dst_h, int src_step, int src_height, uint16_t *resize_buf)
{
	int i;

	float scaley = 1.0 * src_h/dst_h;
	int uv_height = dst_h >> 1;
	int width  = dst_w;
	int fy = 0;

	unsigned char *src_data = NULL;
	unsigned char *vrd_data = NULL;
	for(i = 0 ; i < dst_h; i++) {
		fy = i * scaley;
		vrd_data = dst + i*dst_w;
		src_data  = src + fy*src_w;
		memcpy(vrd_data,src_data,width);
	}
	dst += dst_w * dst_h;
	src += src_w * src_h;
	for(i = 0 ; i < uv_height; i++) {
		fy = i * scaley;
		vrd_data = dst + i*dst_w;
		src_data  = src + fy*src_w;
		memcpy(vrd_data,src_data,width);
	}
}

static void c_resize_simd_nv12_720_to_D1_near_down(uint8_t* src, uint8_t* dst, int src_w, int src_h, int dst_w, int dst_h, int src_step, int src_height, uint16_t *resize_buf)
{
	float scalex = 1.0 * src_w / dst_w;
	float scaley = 1.0 * src_h / dst_h;

	int height = dst_h + (dst_h >> 1);
	int width  = dst_w;

	int i,j,l;

	uint16_t *coordx, *coordy, *cond;
	coordx = resize_buf;
	coordy = resize_buf + (dst_w * 2 + src_h * 3);
	cond = resize_buf + (height * 2);

	v16u8 set0000;
	MFCPU(b, set0000, 0x0);

	float fx, fy;
	int ix, iy;
	memset(cond, 0, sizeof(uint16_t) * C_MAX_WH);

	for(i = 0; i < width; i++)
	{
		fx = (i + 0.5) * scalex - 0.5;
		ix = (int)fx;
		coordx[i] = ix;
		cond[ix] = 1;
		//printf("%d, ",ix);
	}
	//printf("\n");
	for(j = 0 ; j < dst_h; j++)
	{
		fy = (j + 0.5) * scaley - 0.5;
		iy = (int)fy;
		coordy[j] = iy;
	}

	uint8_t k[16],kk[16];
	uint16_t *condition = cond;
	memset(kk, 0, sizeof(kk));

	k[0] = 0;
	for(i = 1; i < 16; i++)
		k[i] = k[i-1]+2;

	int num = src_w>>4;
	v8u16 vector[num];
	uint16_t indx[num];
	int vi = 0;
#define DIFF_VECTOR 0
#if DIFF_VECTOR/*vector[i] is different from vector[i+1]*/
	while(vi<num)
	{
		//printf("vector[%d]:",vi);
		indx[vi] = 0;
		for(i = 0, j = 0; i < 16; i++)
		{
			if(condition[i])
			{
				kk[j] = k[i];
				//printf("%d, ",kk[j]);
				j++;
				indx[vi]++;
			}
		}
		//printf("__%d\n",indx[vi]);
		condition+=16;
		LU1Q(vector[vi], kk, 0);
		vi++;
	}
#else/*all the vector is different*/
	indx[0] = 0;
	for(i = 0, j = 0; i < 16; i++)
	{
		if(condition[i])
		{
			kk[j] = k[i];
			j++;
			indx[0]++;
		}
	}
	LU1Q(vector[0], kk, 0);
#endif
	int loop1 = src_w >> 4;

	uint8_t* data;
	uint8_t* vrd_data;

	v16u8 vrc1;
	v8u16 vrd1;
	//-------------------------------------Y-----------------------------//
	for(i = 0; i < dst_h; i++)
	{
		data = src + src_step * coordy[i];
		vrd_data = dst + dst_w * i;

		for(l = 0; l < loop1 ; l++)
		{
#if DIFF_VECTOR
			LU1Q(vrc1, data, 0);
			SHUFV(vrd1,set0000,vrc1,vector[l]);
			SU1Q(vrd1,vrd_data,0);
			data+=16;
			vrd_data+=indx[l];
#else
			LU1Q(vrc1, data, 0);
			SHUFV(vrd1,set0000,vrc1,vector[0]);
			SU1Q(vrd1,vrd_data,0);
			data+=16;
			vrd_data+=indx[0];

#endif
		}
	}
	//----------------------------end Y---------------------------------//
	//----------------------------U V----------------------------------//
	width = dst_w >> 1;
	height = dst_h >> 1;
	memset(cond, 0, sizeof(uint16_t) * C_MAX_WH);
	for(i = 0; i < width; i++)
	{
		fx = (i + 0.5) * scalex - 0.5;
		ix = (int)fx;
		coordx[i << 1] = ix << 1;
		coordx[(i << 1) + 1] = (ix << 1) + 1;
		cond[ix << 1] = cond[(ix << 1) + 1] = 1;
	}
	//printf("\n");
	for(j = 0 ; j < height; j++)
	{
		fy = (j + 0.5) * scaley - 0.5;
		iy = (int)fy;
		coordy[j] = iy;
	}

	vi = 0;
	while(vi<num)
	{
		//printf("vector[%d]:",vi);
		indx[vi] = 0;
		for(i = 0, j = 0; i < 16; i++)
		{
			if(cond[i])
			{
				kk[j] = k[i];
				//printf("%d, ",kk[j]);
				j++;
				indx[vi]++;
			}
		}
		//printf("__%d\n",indx[vi]);
		cond+=16;
		LU1Q(vector[vi], kk, 0);
		vi++;
	}

	for(i = 0; i < height-1; i++)
	{
		data = src + src_step * (coordy[i] + src_height);
		vrd_data = dst + dst_w * (i + dst_h);
		for(l = 0; l < loop1 ; l++)
		{
			LU1Q(vrc1, data, 0);
			SHUFV(vrd1,set0000,vrc1,vector[l]);
			SU1Q(vrd1,vrd_data,0);
			data+=16;
			vrd_data+=indx[l];
		}
	}
	for(; i < height; i++)//last_line
	{
		data = src + src_step * (coordy[i] + src_height);
		vrd_data = dst + dst_w * (i + dst_h);
		int proNum = 0;
		for(l = 0; (l < loop1)&&(proNum <= dst_w-16); l++)
		{
			LU1Q(vrc1, data + (l<<4), 0);
			SHUFV(vrd1,set0000,vrc1,vector[l]);
			SU1Q(vrd1,vrd_data + proNum,0);
			proNum += indx[l];
		}
		for(;proNum < dst_w; proNum+=2)
		{
			vrd_data[proNum] = data[coordx[proNum]];
			vrd_data[proNum+1] = data[coordx[proNum+1]];
		}
	}
}

//resize_buf = (uint16_t*)malloc(sizeof(uint16_t) * (dst_h * 6 + dst_w * 4 + C_MAX_WH));
static void c_resize_simd_nv12_up(uint8_t* src, uint8_t* dst, int src_w, int src_h, int dst_w, int dst_h, int src_step, int src_height, uint16_t *resize_buf)
{

	int i,j,l,l1;
	float scalex = 1.0 * src_w / dst_w;
	float scaley = 1.0 * src_h / dst_h;

	int height = dst_h + (dst_h >> 1);
	int width  = dst_w;
	//int UV_width = dst_w >> 1;

	uint16_t *x_weightl, *x_weightr, *y_weightl, *y_weightr, *coordx, *coordx1, *coordy, *coordy1, *cond;
	x_weightl = resize_buf;
	x_weightr = resize_buf + dst_w;
	coordx = resize_buf + (dst_w << 1);
	coordx1 = resize_buf + (dst_w * 3);

	y_weightl = resize_buf + (dst_w * 4);
	y_weightr = resize_buf + (dst_w * 4 + height);
	coordy = resize_buf + (dst_w * 4 + height *2);
	coordy1 = resize_buf + (dst_w *4 + height *3);
	cond = resize_buf + (dst_w *4 + height *4);

	v16u8 convx1, convx2, set0000, convx11 = _mx128_li_b(0), set0004, set0008;
	int vec_sel[8] = {0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514, 0x1b1a1918, 0x1f1e1d1c};
	LU1Q(convx1,vec_sel,0);
	LU1Q(convx2,vec_sel,16);

	int k0,k1,k2,k3;
	k0 = 0x0E0A0602;
	k1 = 0x1E1A1612;
	k2 = 0x0F0B0703;
	k3 = 0x1F1B1713;

	INSFCPU(w,convx11,0,k0);
	INSFCPU(w,convx11,1,k1);
	INSFCPU(w,convx11,2,k2);
	INSFCPU(w,convx11,3,k3);

	MFCPU(b, set0000, 0x0);
	MFCPU(h, set0004, 0x4);
	MFCPU(h, set0008, 0x8);

	float fx, fy;
	int ix, iy;
	memset(cond, 0, sizeof(uint16_t) * C_MAX_WH);

	for(i = 0; i < width; i++)
	{
		fx = i * scalex;
		ix = (int)fx;
		x_weightr[i] = (uint16_t)((fx - ix)*16 + 0.5);
		x_weightl[i] = 16 - x_weightr[i];
		cond[ix]++;
		coordx[i] = ix;
		if(ix < src_w - 1)
			coordx1[i] = ix + 1;
		else coordx1[i] = ix;
	}

	for(j = 0 ; j < dst_h; j++)
	{
		fy = j * scaley;
		iy = (int)fy;
		y_weightr[j] = (uint16_t)((fy - iy)*16 + 0.5);
		y_weightl[j] = 16 - y_weightr[j];
		coordy[j] = iy;
		if(iy < src_h - 1) coordy1[j] = iy + 1;
		else coordy1[j] = iy;
	}

	v8u16 vector[162];
	uint16_t indx[162];
	int num = 162;
	unsigned char k[16],kk[16];
	uint16_t *condition = cond;
	memset(kk, 0, sizeof(kk));

	k[0] = 0;
	for(i = 1; i < 16; i++)
		k[i] = k[i-1]+2;


	while(num)
	{
		int t = 162 - num;
		indx[t] = 0;
		int s = 0;

		for(i = 0,j = 0; i < 16; j++)
		{
			if(condition[j] > 0)
			{
				while( condition[j] )
				{
					kk[i++] = s;
					--condition[j];
					if(i >= 16) break;
				}
				if(!condition[j]) {
				indx[t]++;
				s+=2;}
			}
			else break;

		}

		if(i < 16) break;
		condition+=indx[t];
		LU1Q(vector[t], kk, 0);
		num--;
	}

	v8u16 xweightl, xweightr, yweightl, yweightr;

	v16u8 vrc1,vrc2, vrc_1, vrc_2;

	v8u16 vrd11,vrd12,vrd21,vrd22, vrd_11,vrd_12,vrd_21,vrd_22;

	v8u16 R1, R2;


	uint16_t* ptr_xweightl;
	uint16_t* ptr_xweightr;
	//uint16_t* ptr_yweightl;
	//uint16_t* ptr_yweightr;
	const unsigned char* data;
	const unsigned char* data1;
	unsigned char* vrd_data;

	int loop = (dst_w - 1) >> 4;
	int loop1 = width - (loop << 4);
//------------------------Y--------------------------------------------------//
	for(i = 0; i < dst_h; i++)
	{//for1
		ptr_xweightl = x_weightl;
		ptr_xweightr = x_weightr;
		//ptr_yweightl = y_weightl;
		//ptr_yweightr = y_weightr;

		data = src + src_step * coordy[i];
		data1 = src + src_step * coordy1[i];
		vrd_data = dst + dst_w * i;
		MFCPU(h, yweightl, y_weightl[i]);
 		MFCPU(h, yweightr, y_weightr[i]);
		if(y_weightr[i])
		{//if
			for(l = 0; l < loop; l++)
			{//for2
				LU1Q(vrc1, data, 0);
				LU1Q(vrc2, data, 1);
				data += indx[l];

				LU1Q(vrc_1, data1, 0);
				LU1Q(vrc_2, data1, 1);
				data1 += indx[l];

				SHUFV(vrc1,vrc1,vrc1,vector[l]);
				SHUFV(vrc2,vrc2,vrc2,vector[l]);

				SHUFV(vrc_1,vrc_1,vrc_1,vector[l]);
				SHUFV(vrc_2,vrc_2,vrc_2,vector[l]);

				SHUFV(vrd11,set0000,vrc1,convx1);
     		        	SHUFV(vrd12,set0000,vrc1,convx2);
      				SHUFV(vrd21,set0000,vrc2,convx1);
      				SHUFV(vrd22,set0000,vrc2,convx2);

      				SHUFV(vrd_11,set0000,vrc_1,convx1);
      				SHUFV(vrd_12,set0000,vrc_1,convx2);
      				SHUFV(vrd_21,set0000,vrc_2,convx1);
      				SHUFV(vrd_22,set0000,vrc_2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				MUL(h, vrd_11, xweightl, vrd_11);
				MUL(h, vrd_21, xweightr, vrd_21);

				MUL(h, vrd11, vrd11, yweightl);
				MUL(h, vrd21, vrd21, yweightl);

				MUL(h, vrd_11, vrd_11, yweightr);
				MUL(h, vrd_21, vrd_21, yweightr);

				ADDUU(h, vrd_11, vrd_11, vrd_21);
				ADDUU(h, vrd11, vrd11, vrd21);
				ADDUU(h, R1, vrd_11, vrd11);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				MUL(h, vrd_12, xweightl, vrd_12);
				MUL(h, vrd_22, xweightr, vrd_22);

				MUL(h, vrd12, vrd12, yweightl);
				MUL(h, vrd22, vrd22, yweightl);

				MUL(h, vrd_12, vrd_12, yweightr);
				MUL(h, vrd_22, vrd_22, yweightr);

				ADDUU(h, vrd_12, vrd_12, vrd_22);
				ADDUU(h, vrd12, vrd12, vrd22);
				ADDUU(h, R2, vrd_12, vrd12);

				SHUFV(R1,R2,R1,convx11);

				SU1Q(R1,vrd_data,0);
				ptr_xweightl+=16;
				ptr_xweightr+=16;

				vrd_data+=16;
			}//for2

			l <<= 4;
			data = src + src_step * coordy[i];
			data1 = src + src_step * coordy1[i];
			for(l1 = 0 ; l1 < loop1; l1++,l++)
			{
				int value = data[coordx[l]]*x_weightl[l]*y_weightl[i] + data[coordx1[l]]*x_weightr[l]*y_weightl[i] +
						data1[coordx[l]]*x_weightl[l]*y_weightr[i] + data1[coordx1[l]]*x_weightr[l]*y_weightr[i];
				vrd_data[l1] = value>>8;



			}
		}//end if
		else
		{//else
			for(l = 0; l < loop; l++)
    			{
				LU1Q(vrc1, data, 0);
  		   	 	LU1Q(vrc2, data, 1);
				data += indx[l];

				SHUFV(vrc1,vrc1,vrc1,vector[l]);
				SHUFV(vrc2,vrc2,vrc2,vector[l]);

    		   	 	SHUFV(vrd11,set0000,vrc1,convx1);
     		        	SHUFV(vrd12,set0000,vrc1,convx2);
      				SHUFV(vrd21,set0000,vrc2,convx1);
      				SHUFV(vrd22,set0000,vrc2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				ADDUU(h, R1, vrd11, vrd21);
				SLL(h, R1, R1, set0004);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				ADDUU(h, R2, vrd12, vrd22);
				SLL(h, R2, R2, set0004);

				SHUFV(R1,R2,R1,convx11);

				SU1Q(R1,vrd_data,0);

				ptr_xweightl+=16;
				ptr_xweightr+=16;

				vrd_data+=16;
			}


			l <<= 4;
			data = src + src_step * coordy[i];
			for(l1 = 0 ; l1 < loop1; l1++,l++)
			{
				int value = data[coordx[l]]*x_weightl[l] + data[coordx1[l]]*x_weightr[l];
				vrd_data[l1] = value>>4;
			}
		}//end else
	}//for1

//-----------------------------------end Y------------------------------------------------//

//-----------------------------------U V-------------------------------------------------//
	width = dst_w;
	height = dst_h >> 1;
	memset(cond, 0, sizeof(uint16_t) * C_MAX_WH);
	for(i = 0; i < (width>>1); i++)
	{
		fx = i * scalex;
		ix = (int)fx;
		x_weightr[(i<<1) + 1] = x_weightr[i<<1] = (uint16_t)((fx - ix)*16 + 0.5);
		x_weightl[(i<<1) + 1] = x_weightl[i<<1] = 16 - x_weightr[i << 1];
		cond[ix]++;
		coordx[i] = ix;
		if(ix < (src_w >> 1) - 1){
			coordx1[i] = ix + 1;
		}
		else{
		 coordx1[i] = ix;
		}
	}

	for(j = 0 ; j < height; j++)
	{
		fy = j * scaley;
		iy = (int)fy;
		y_weightr[j] = (uint16_t)((fy - iy)*16 + 0.5);
		y_weightl[j] = 16 - y_weightr[j];
		coordy[j] = iy + src_height;
		if(iy < (src_h >> 1) - 1) coordy1[j] = iy + src_height + 1;
		else coordy1[j] = iy + src_height;
	}


	loop = ((width - 2) >> 4);
	loop1 = width - (loop << 4);
	k[0] = 0;
	for(i = 1; i < 16; i++)
		k[i] = k[i-1]+2;

	condition = cond;
	memset(kk, 0, sizeof(kk));
	num = 162;
	while(num)
	{
		int t = 162 - num;
		indx[t] = 0;
		int s = 0;

		for(i = 0,j = 0; i < 16; j++)
		{
			if(condition[j] > 0)
			{
				while( condition[j] )
				{
					kk[i++] = s;
					kk[i++] = s+2;
					--condition[j];
					if(i >= 15) break;
				}
				if(!condition[j]) {
				indx[t]++;
				s+=4;}
			}
			else break;

		}

		if(i < 16) break;
		condition+=indx[t];
		indx[t]*=2;
		LU1Q(vector[t], kk, 0);
		num--;
	}
	for(i = 0; i < height; i++)
	{//for1
		ptr_xweightl = x_weightl;
		ptr_xweightr = x_weightr;
		//ptr_yweightl = y_weightl;
		//ptr_yweightr = y_weightr;

		data = src + src_step * coordy[i];
		data1 = src + src_step * coordy1[i];
		vrd_data = dst + dst_w * (i + dst_h);

		MFCPU(h, yweightl, y_weightl[i]);
 		MFCPU(h, yweightr, y_weightr[i]);
		if(y_weightr[i])
		{//if
			for(l = 0; l < loop; l++)
			{//for2
				LU1Q(vrc1, data, 0);
				LU1Q(vrc2, data, 2);
				data += indx[l];

				LU1Q(vrc_1, data1, 0);
				LU1Q(vrc_2, data1, 2);
				data1 += indx[l];

				SHUFV(vrc1,vrc1,vrc1,vector[l]);
				SHUFV(vrc2,vrc2,vrc2,vector[l]);

				SHUFV(vrc_1,vrc_1,vrc_1,vector[l]);
				SHUFV(vrc_2,vrc_2,vrc_2,vector[l]);

				SHUFV(vrd11,set0000,vrc1,convx1);
     		        	SHUFV(vrd12,set0000,vrc1,convx2);
      				SHUFV(vrd21,set0000,vrc2,convx1);
      				SHUFV(vrd22,set0000,vrc2,convx2);

      				SHUFV(vrd_11,set0000,vrc_1,convx1);
      				SHUFV(vrd_12,set0000,vrc_1,convx2);
      				SHUFV(vrd_21,set0000,vrc_2,convx1);
      				SHUFV(vrd_22,set0000,vrc_2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				MUL(h, vrd_11, xweightl, vrd_11);
				MUL(h, vrd_21, xweightr, vrd_21);

				MUL(h, vrd11, vrd11, yweightl);
				MUL(h, vrd21, vrd21, yweightl);

				MUL(h, vrd_11, vrd_11, yweightr);
				MUL(h, vrd_21, vrd_21, yweightr);

				ADDUU(h, vrd_11, vrd_11, vrd_21);
				ADDUU(h, vrd11, vrd11, vrd21);
				ADDUU(h, R1, vrd_11, vrd11);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				MUL(h, vrd_12, xweightl, vrd_12);
				MUL(h, vrd_22, xweightr, vrd_22);

				MUL(h, vrd12, vrd12, yweightl);
				MUL(h, vrd22, vrd22, yweightl);

				MUL(h, vrd_12, vrd_12, yweightr);
				MUL(h, vrd_22, vrd_22, yweightr);

				ADDUU(h, vrd_12, vrd_12, vrd_22);
				ADDUU(h, vrd12, vrd12, vrd22);
				ADDUU(h, R2, vrd_12, vrd12);

				SHUFV(R1,R2,R1,convx11);

				SU1Q(R1,vrd_data,0);
				ptr_xweightl+=16;
				ptr_xweightr+=16;

				vrd_data+=16;
			}//for2

			l <<= 4;
			data = src + src_step * coordy[i];
			data1 = src + src_step * coordy1[i];
			for(l1 = 0 ; l1 < loop1; l1+=2,l+=2)
			{
				int half = l >> 1;
				int ind = coordx[half] << 1;
				int ind1 = coordx1[half] << 1;
				int value = data[ind]*x_weightl[l]*y_weightl[i] + data[ind1]*x_weightr[l]*y_weightl[i] +
						data1[ind]*x_weightl[l]*y_weightr[i] + data1[ind1]*x_weightr[l]*y_weightr[i];
				vrd_data[l1] = value>>8;

				value = data[ind + 1]*x_weightl[l + 1]*y_weightl[i] + data[ind1 + 1]*x_weightr[l + 1]*y_weightl[i] +
						data1[ind + 1]*x_weightl[l + 1]*y_weightr[i] + data1[ind1 + 1]*x_weightr[l + 1]*y_weightr[i];
				vrd_data[l1+1] = value>>8;
			}
		}//end if
		else
		{//else
			for(l = 0; l < loop; l++)
    			{
				LU1Q(vrc1, data, 0);
  		   	 	LU1Q(vrc2, data, 2);
				data += indx[l];

				SHUFV(vrc1,vrc1,vrc1,vector[l]);
				SHUFV(vrc2,vrc2,vrc2,vector[l]);

    		   	 	SHUFV(vrd11,set0000,vrc1,convx1);
     		        	SHUFV(vrd12,set0000,vrc1,convx2);
      				SHUFV(vrd21,set0000,vrc2,convx1);
      				SHUFV(vrd22,set0000,vrc2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				ADDUU(h, R1, vrd11, vrd21);
				SLL(h, R1, R1, set0004);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				ADDUU(h, R2, vrd12, vrd22);
				SLL(h, R2, R2, set0004);

				SHUFV(R1,R2,R1,convx11);

				SU1Q(R1,vrd_data,0);

				ptr_xweightl+=16;
				ptr_xweightr+=16;

				vrd_data+=16;
			}

			l <<= 4;
			data = src + src_step * coordy[i];
			for(l1 = 0 ; l1 < loop1; l1+=2,l+=2)
			{
				int half = l >> 1;
				int ind = coordx[half] << 1;
				int ind1 = coordx1[half] << 1;
				int value = data[ind]*x_weightl[l] + data[ind1]*x_weightr[l];
				vrd_data[l1] = value>>4;
				value = data[ind + 1]*x_weightl[l] + data[ind1 + 1]*x_weightr[l];
				vrd_data[l1 + 1] = value>>4;
			}
		}//end else
	}//for1
}

//resize_buf=(uint16_t *)malloc(sizeof(uint16_t) * (src_w * 3 + dst_w * 2 + src_h * 3 + dst_h * 3 + C_MAX_WH));
static void c_resize_simd_nv12_down(uint8_t* src, uint8_t* dst, int src_w, int src_h, int dst_w, int dst_h, int src_step, int src_height, uint16_t *resize_buf)
{
	float scalex = 1.0 * src_w / dst_w;
	float scaley = 1.0 * src_h / dst_h;
	int height = dst_h + (dst_h >> 1);
	int width  = dst_w;
	int i,j,l;

	uint16_t *x_weightl, *x_weightr, *y_weightl, *y_weightr, *coordx, *coordx1, *coordy, *coordy1, *cond;
	x_weightl = resize_buf;
	x_weightr = resize_buf + src_w;
	coordx = resize_buf + (src_w * 2);
	coordx1 = resize_buf + (src_w * 2 + dst_w);

	y_weightl = resize_buf + (src_w * 2 + dst_w * 2);
	y_weightr = resize_buf + (src_w * 2 + dst_w * 2 + src_h + (src_h >> 1));
	coordy = resize_buf + (src_w * 2 + dst_w * 2 + src_h * 3);
	coordy1 = resize_buf + (src_w * 2 + dst_w * 2 + src_h * 3 + height);
	cond = resize_buf + (src_w * 2 + dst_w * 2 + src_h * 3 + height * 2);

	v16u8 convx1, convx2, convx11 = _mx128_li_b(0), set0000, set0004, set0008;
	int vec_sel[8] = {0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, 0x13121110, 0x17161514, 0x1b1a1918, 0x1f1e1d1c};
	LU1Q(convx1,vec_sel,0);
	LU1Q(convx2,vec_sel,16);

	int k0,k1,k2,k3;
	k0 = 0x0E0A0602;
	k1 = 0x1E1A1612;
	k2 = 0x0F0B0703;
	k3 = 0x1F1B1713;

	INSFCPU(w,convx11,0,k0);
	INSFCPU(w,convx11,1,k1);
	INSFCPU(w,convx11,2,k2);
	INSFCPU(w,convx11,3,k3);

	MFCPU(b, set0000, 0x0);
	MFCPU(h, set0004, 0x4);
	MFCPU(h, set0008, 0x8);

	float fx, fy;
	int ix, iy;
	memset(cond, 0, sizeof(uint16_t) * C_MAX_WH);

	for(i = 0; i < width; i++)
	{
		fx = (i + 0.5) * scalex - 0.5;
		ix = (int)fx;
		x_weightr[ix] = (uint16_t)((fx - ix)*16 + 0.5);
		x_weightl[ix] = 16 - x_weightr[ix];
		coordx[i] = ix;
		cond[ix] = 1;
		if(ix < src_w - 1)
			coordx1[i] = ix + 1;
		else coordx1[i] = ix;
	}

	for(j = 0 ; j < dst_h; j++)
	{
		fy = (j + 0.5) * scaley - 0.5;
		iy = (int)fy;
		y_weightr[iy] = (uint16_t)((fy - iy)*16 + 0.5);
		y_weightl[iy] = 16 - y_weightr[iy];
		coordy[j] = iy;
		if(iy < src_h - 1) coordy1[j] = iy + 1;
		else coordy1[j] = iy;
	}
	v8u16 vector[162];
	uint16_t indx[162];
	int num = 162, num1;
	unsigned char k[16],kk[16];
	uint16_t *condition = cond;
	memset(kk, 0, sizeof(kk));

	k[0] = 2;
	for(i = 1; i < 8; i++)
		k[i] = k[i-1]+4;

	k[8] = 3;
	for(i = 9; i < 16; i++)
		k[i] = k[i-1]+4;

	while(num)
	{
		indx[162-num] = 16;
		for(i = 0, j = 0; i < 16; i++)
		{
			if(condition[i] == 0)
			{
				indx[162-num]--;
				continue;
			}
			else
			{
				kk[j] = k[i];
				j++;
			}
		}

		condition+=16;
		LU1Q(vector[162-num], kk, 0);
		num--;
	}

	int sloop = src_w>>4;
	int data_left = dst_w;
	if(src==dst)
		data_left = src_w;
	int dloop = 0;
	int dnum = 0;

	for(num = 0, i = 0; i < sloop; i++)
	{
		num += indx[i];
		data_left -= indx[i];
		//avoid cross boundary in dst(just for last 16 data)
		if(data_left > 15)
		{
			dloop = i+1;
			dnum = num;
		}
	}
	if(src!=dst)
	{
		dloop = sloop;
		dnum = num;
	}

	uint16_t* ptr_xweightl;
	uint16_t* ptr_xweightr;
	const unsigned char* data;
	const unsigned char* data1;
	unsigned char* vrd_data;

	v8u16 xweightl, xweightr, yweightl, yweightr;
	v16u8 vrc1, vrc2, vrc_1, vrc_2;
	v8u16 vrd11,vrd12,vrd21,vrd22, vrd_11,vrd_12,vrd_21,vrd_22;
	v8u16 R1, R2;
//-------------------------------------Y-----------------------------//
	for(i = 0; i < dst_h; i++)
	{
		ptr_xweightl = x_weightl;
		ptr_xweightr = x_weightr;
		data = src + src_step * coordy[i];
		data1 = src + src_step * coordy1[i];
		vrd_data = dst + dst_w * i;
		if(y_weightr[coordy[i]])
		{
			MFCPU(h, yweightl, y_weightl[coordy[i]]);
			MFCPU(h, yweightr, y_weightr[coordy[i]]);
			for(l = 0; l < dloop ; l++)
			{
				LU1Q(vrc1, data, 0);
  		   	 	LU1Q(vrc2, data, 1);

				LU1Q(vrc_1, data1, 0);
   		   	 	LU1Q(vrc_2, data1, 1);

				SHUFV(vrd11,set0000,vrc1,convx1);
				SHUFV(vrd12,set0000,vrc1,convx2);
				SHUFV(vrd21,set0000,vrc2,convx1);
				SHUFV(vrd22,set0000,vrc2,convx2);

				SHUFV(vrd_11,set0000,vrc_1,convx1);
				SHUFV(vrd_12,set0000,vrc_1,convx2);
				SHUFV(vrd_21,set0000,vrc_2,convx1);
				SHUFV(vrd_22,set0000,vrc_2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				MUL(h, vrd_11, xweightl, vrd_11);
				MUL(h, vrd_21, xweightr, vrd_21);

				MUL(h, vrd11, vrd11, yweightl);
				MUL(h, vrd21, vrd21, yweightl);

				MUL(h, vrd_11, vrd_11, yweightr);
				MUL(h, vrd_21, vrd_21, yweightr);

				ADDUU(h, vrd_11, vrd_11, vrd_21);
				ADDUU(h, vrd11, vrd11, vrd21);
				ADDUU(h, R1, vrd_11, vrd11);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				MUL(h, vrd_12, xweightl, vrd_12);
				MUL(h, vrd_22, xweightr, vrd_22);

				MUL(h, vrd12, vrd12, yweightl);
				MUL(h, vrd22, vrd22, yweightl);

				MUL(h, vrd_12, vrd_12, yweightr);
				MUL(h, vrd_22, vrd_22, yweightr);

				ADDUU(h, vrd_12, vrd_12, vrd_22);
				ADDUU(h, vrd12, vrd12, vrd22);
				ADDUU(h, R2, vrd_12, vrd12);

				SHUFV(R1,R2,R1,vector[l]);

				SU1Q(R1,vrd_data,0);
				ptr_xweightl+=16;
				ptr_xweightr+=16;
				data+=16;
				data1+=16;
				vrd_data+=indx[l];
			}
			num1 = dnum;
			data = src + src_step * coordy[i];
			data1 = src + src_step * coordy1[i];
			for(l = 0; num1 < dst_w; num1++,l++)
			{
				int sum = data[coordx[num1]] * x_weightl[coordx[num1]] * y_weightl[coordy[i]] + data[coordx1[num1]] * x_weightr[coordx[num1]] * y_weightl[coordy[i]]
				 + data1[coordx[num1]] * x_weightl[coordx[num1]] * y_weightr[coordy[i]] + data1[coordx1[num1]] * x_weightr[coordx[num1]] * y_weightr[coordy[i]];
				vrd_data[l] = sum >> 8;
			}
		}
		else
		{
			for(l = 0; l < dloop; l++)
    			{
					LU1Q(vrc1, data, 0);
					LU1Q(vrc2, data, 1);

					SHUFV(vrd11,set0000,vrc1,convx1);
					SHUFV(vrd12,set0000,vrc1,convx2);
					SHUFV(vrd21,set0000,vrc2,convx1);
					SHUFV(vrd22,set0000,vrc2,convx2);

					LU1Q(xweightl, ptr_xweightl, 0);
					LU1Q(xweightr, ptr_xweightr, 0);

					MUL(h, vrd11, xweightl, vrd11);
					MUL(h, vrd21, xweightr, vrd21);

					ADDUU(h, R1, vrd11, vrd21);
					SLL(h, R1, R1, set0004);

					LU1Q(xweightl, ptr_xweightl, 16);
					LU1Q(xweightr, ptr_xweightr, 16);

					MUL(h, vrd12, xweightl, vrd12);
					MUL(h, vrd22, xweightr, vrd22);

					ADDUU(h, R2, vrd12, vrd22);
					SLL(h, R2, R2, set0004);

					SHUFV(R1,R2,R1,vector[l]);
					SU1Q(R1,vrd_data,0);

					ptr_xweightl+=16;
					ptr_xweightr+=16;
					data+=16;
					vrd_data+=indx[l];
				}
			num1 = dnum;
			data = src + src_step * coordy[i];
			for(l = 0; num1 < dst_w; num1++,l++)
			{
				int sum = data[coordx[num1]] * x_weightl[coordx[num1]] + data[coordx1[num1]] * x_weightr[coordx[num1]];
				vrd_data[l] = sum >> 4;
			}
		}
	}
//----------------------------end Y---------------------------------//
//----------------------------U V----------------------------------//
	width = dst_w >> 1;
	height = dst_h >> 1;
	memset(cond, 0, sizeof(uint16_t) * C_MAX_WH);
	for(i = 0; i < width; i++)
	{
		fx = (i + 0.5) * scalex - 0.5;
		ix = (int)fx;
		x_weightr[ix << 1] = x_weightr[(ix << 1) + 1] = (uint16_t)((fx - ix)*16 + 0.5);
		x_weightl[ix << 1] = x_weightl[(ix << 1) + 1] = 16 - x_weightr[ix << 1];
		coordx[i << 1] = ix << 1;
		coordx[(i << 1) + 1] = (ix << 1) + 1;
		cond[ix << 1] = cond[(ix << 1) + 1] = 1;
		if(ix < width - 1){
			coordx1[i << 1] = (ix << 1) + 2;
			coordx1[(i << 1) + 1] = (ix << 1) + 3;
		}
		else {
			coordx1[i << 1] = ix << 1;
			coordx1[(i << 1) + 1] = (ix << 1) + 1;
		}

	}
	for(j = 0 ; j < height; j++)
	{
		fy = (j + 0.5) * scaley - 0.5;
		iy = (int)fy;
		y_weightr[iy] = (uint16_t)((fy - iy)*16 + 0.5);
		y_weightl[iy] = 16 - y_weightr[iy];
		coordy[j] = iy;
		if(iy < height - 1) coordy1[j] = iy + 1;
		else coordy1[j] = iy;
	}
	num = 162;
	while(num)
	{
		indx[162-num] = 16;
		for(i = 0, j = 0; i < 16; i++)
		{
			if(cond[i] == 0)
			{
				indx[162-num]--;
				continue;
			}
			else
			{
				kk[j] = k[i];
				j++;
			}
		}
		cond+=16;
		LU1Q(vector[162-num], kk, 0);
		num--;
	}
    /**loop**/
	sloop = src_w>>4;
	data_left = dst_w;
	if(src==dst)
		data_left = src_w;
	dloop = 0;
	dnum = 0;
	int dloop1 = 0, dloop2 = 0;
	int dnum1 = 0, dnum2 = 0;

	for(num = 0, i = 0; i < sloop; i++)
	{
		num += indx[i];
		data_left -= indx[i];
		//avoid cross boundary in dst(just for last 16 data)
		if(data_left > 15)
		{
			dloop = i+1;
			dnum = num;
		}
	}
	if(src!=dst)
	{
		dloop1 = sloop;
		dloop2 = dloop;
		dnum1 = num;
		dnum2 = dnum;
	}
	else
	{
		dloop1 = dloop;
		dloop2 = dloop;
		dnum1 = dnum;
		dnum2 = dnum;
	}
	for(i = 0; i < height-1; i++)
	{
		ptr_xweightl = x_weightl;
		ptr_xweightr = x_weightr;
		data = src + src_step * (coordy[i] + src_height);
		data1 = src + src_step * (coordy1[i] + src_height);
		vrd_data = dst + dst_w * (i + dst_h);
		MFCPU(h, yweightl, y_weightl[coordy[i]]);
 		MFCPU(h, yweightr, y_weightr[coordy[i]]);
		if(y_weightr[coordy[i]])
		{
			for(l = 0; l < dloop1 ; l++)
			{
				LU1Q(vrc1, data, 0);
  		   	 	LU1Q(vrc2, data, 2);

				LU1Q(vrc_1, data1, 0);
   		   	 	LU1Q(vrc_2, data1, 2);

				SHUFV(vrd11,set0000,vrc1,convx1);
				SHUFV(vrd12,set0000,vrc1,convx2);
				SHUFV(vrd21,set0000,vrc2,convx1);
				SHUFV(vrd22,set0000,vrc2,convx2);

				SHUFV(vrd_11,set0000,vrc_1,convx1);
				SHUFV(vrd_12,set0000,vrc_1,convx2);
				SHUFV(vrd_21,set0000,vrc_2,convx1);
				SHUFV(vrd_22,set0000,vrc_2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				MUL(h, vrd_11, xweightl, vrd_11);
				MUL(h, vrd_21, xweightr, vrd_21);

				MUL(h, vrd11, vrd11, yweightl);
				MUL(h, vrd21, vrd21, yweightl);

				MUL(h, vrd_11, vrd_11, yweightr);
				MUL(h, vrd_21, vrd_21, yweightr);

				ADDUU(h, vrd_11, vrd_11, vrd_21);
				ADDUU(h, vrd11, vrd11, vrd21);
				ADDUU(h, R1, vrd_11, vrd11);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				MUL(h, vrd_12, xweightl, vrd_12);
				MUL(h, vrd_22, xweightr, vrd_22);

				MUL(h, vrd12, vrd12, yweightl);
				MUL(h, vrd22, vrd22, yweightl);

				MUL(h, vrd_12, vrd_12, yweightr);
				MUL(h, vrd_22, vrd_22, yweightr);

				ADDUU(h, vrd_12, vrd_12, vrd_22);
				ADDUU(h, vrd12, vrd12, vrd22);
				ADDUU(h, R2, vrd_12, vrd12);

				SHUFV(R1,R2,R1,vector[l]);
				SU1Q(R1,vrd_data,0);
				ptr_xweightl+=16;
				ptr_xweightr+=16;
				data+=16;
				data1+=16;
				vrd_data+=indx[l];
			}
			num1 = dnum1;
			data = src + src_step * (coordy[i] + src_height);
			data1 = src + src_step * (coordy1[i] + src_height);
			for(l = 0; num1 < dst_w; num1++)
			{
				int sum = data[coordx[num1]] * x_weightl[coordx[num1]] * y_weightl[coordy[i]] + data[coordx1[num1]] * x_weightr[coordx[num1]] * y_weightl[coordy[i]]
					+ data1[coordx[num1]] * x_weightl[coordx[num1]] * y_weightr[coordy[i]] + data1[coordx1[num1]] * x_weightr[coordx[num1]] * y_weightr[coordy[i]];
				vrd_data[l++] = sum >> 8;
			}
		}
		else
		{
			for(l = 0; l < dloop1; l++)
			{
				LU1Q(vrc1, data, 0);
  		   	 	LU1Q(vrc2, data, 2);

				SHUFV(vrd11,set0000,vrc1,convx1);
				SHUFV(vrd12,set0000,vrc1,convx2);
				SHUFV(vrd21,set0000,vrc2,convx1);
				SHUFV(vrd22,set0000,vrc2,convx2);

				LU1Q(xweightl, ptr_xweightl, 0);
				LU1Q(xweightr, ptr_xweightr, 0);

				MUL(h, vrd11, xweightl, vrd11);
				MUL(h, vrd21, xweightr, vrd21);

				ADDUU(h, R1, vrd11, vrd21);
				SLL(h, R1, R1, set0004);

				LU1Q(xweightl, ptr_xweightl, 16);
				LU1Q(xweightr, ptr_xweightr, 16);

				MUL(h, vrd12, xweightl, vrd12);
				MUL(h, vrd22, xweightr, vrd22);

				ADDUU(h, R2, vrd12, vrd22);
				SLL(h, R2, R2, set0004);

				SHUFV(R1,R2,R1,vector[l]);
				SU1Q(R1,vrd_data,0);

				ptr_xweightl+=16;
				ptr_xweightr+=16;
				data+=16;
				vrd_data+=indx[l];
			}
			data = src + src_step * (coordy[i] + src_height);
			num1 = dnum1;
			for(l = 0; num1 < dst_w; num1++)
			{
				int sum = data[coordx[num1]] * x_weightl[coordx[num1]] + data[coordx1[num1]] * x_weightr[coordx[num1]];
				vrd_data[l++] = sum >> 4;
			}
		}
	}
//----------------------------last U V----------------------------------//
	ptr_xweightl = x_weightl;
	ptr_xweightr = x_weightr;
	data = src + src_step * (coordy[i] + src_height);
	data1 = src + src_step * (coordy1[i] + src_height);
	vrd_data = dst + dst_w * (i + dst_h);
	MFCPU(h, yweightl, y_weightl[coordy[i]]);
	MFCPU(h, yweightr, y_weightr[coordy[i]]);
	if(y_weightr[coordy[i]])
	{
		for(l = 0; l < dloop2 ; l++)
		{
			LU1Q(vrc1, data, 0);
			LU1Q(vrc2, data, 2);

			LU1Q(vrc_1, data1, 0);
			LU1Q(vrc_2, data1, 2);

			SHUFV(vrd11,set0000,vrc1,convx1);
			SHUFV(vrd12,set0000,vrc1,convx2);
			SHUFV(vrd21,set0000,vrc2,convx1);
			SHUFV(vrd22,set0000,vrc2,convx2);

			SHUFV(vrd_11,set0000,vrc_1,convx1);
			SHUFV(vrd_12,set0000,vrc_1,convx2);
			SHUFV(vrd_21,set0000,vrc_2,convx1);
			SHUFV(vrd_22,set0000,vrc_2,convx2);

			LU1Q(xweightl, ptr_xweightl, 0);
			LU1Q(xweightr, ptr_xweightr, 0);

			MUL(h, vrd11, xweightl, vrd11);
			MUL(h, vrd21, xweightr, vrd21);

			MUL(h, vrd_11, xweightl, vrd_11);
			MUL(h, vrd_21, xweightr, vrd_21);

			MUL(h, vrd11, vrd11, yweightl);
			MUL(h, vrd21, vrd21, yweightl);

			MUL(h, vrd_11, vrd_11, yweightr);
			MUL(h, vrd_21, vrd_21, yweightr);

			ADDUU(h, vrd_11, vrd_11, vrd_21);
			ADDUU(h, vrd11, vrd11, vrd21);
			ADDUU(h, R1, vrd_11, vrd11);

			LU1Q(xweightl, ptr_xweightl, 16);
			LU1Q(xweightr, ptr_xweightr, 16);

			MUL(h, vrd12, xweightl, vrd12);
			MUL(h, vrd22, xweightr, vrd22);

			MUL(h, vrd_12, xweightl, vrd_12);
			MUL(h, vrd_22, xweightr, vrd_22);

			MUL(h, vrd12, vrd12, yweightl);
			MUL(h, vrd22, vrd22, yweightl);

			MUL(h, vrd_12, vrd_12, yweightr);
			MUL(h, vrd_22, vrd_22, yweightr);

			ADDUU(h, vrd_12, vrd_12, vrd_22);
			ADDUU(h, vrd12, vrd12, vrd22);
			ADDUU(h, R2, vrd_12, vrd12);

			SHUFV(R1,R2,R1,vector[l]);
			SU1Q(R1,vrd_data,0);
			ptr_xweightl+=16;
			ptr_xweightr+=16;
			data+=16;
			data1+=16;
			vrd_data+=indx[l];
		}
		num1 = dnum2;
		data = src + src_step * (coordy[i] + src_height);
		data1 = src + src_step * (coordy1[i] + src_height);
		for(l = 0; num1 < dst_w; num1++)
		{
			int sum = data[coordx[num1]] * x_weightl[coordx[num1]] * y_weightl[coordy[i]] + data[coordx1[num1]] * x_weightr[coordx[num1]] * y_weightl[coordy[i]]
				+ data1[coordx[num1]] * x_weightl[coordx[num1]] * y_weightr[coordy[i]] + data1[coordx1[num1]] * x_weightr[coordx[num1]] * y_weightr[coordy[i]];
			vrd_data[l++] = sum >> 8;
		}
	}
	else
	{
		for(l = 0; l < dloop2; l++)
		{
			LU1Q(vrc1, data, 0);
			LU1Q(vrc2, data, 2);

			SHUFV(vrd11,set0000,vrc1,convx1);
			SHUFV(vrd12,set0000,vrc1,convx2);
			SHUFV(vrd21,set0000,vrc2,convx1);
			SHUFV(vrd22,set0000,vrc2,convx2);

			LU1Q(xweightl, ptr_xweightl, 0);
			LU1Q(xweightr, ptr_xweightr, 0);

			MUL(h, vrd11, xweightl, vrd11);
			MUL(h, vrd21, xweightr, vrd21);

			ADDUU(h, R1, vrd11, vrd21);
			SLL(h, R1, R1, set0004);

			LU1Q(xweightl, ptr_xweightl, 16);
			LU1Q(xweightr, ptr_xweightr, 16);

			MUL(h, vrd12, xweightl, vrd12);
			MUL(h, vrd22, xweightr, vrd22);

			ADDUU(h, R2, vrd12, vrd22);
			SLL(h, R2, R2, set0004);

			SHUFV(R1,R2,R1,vector[l]);
			SU1Q(R1,vrd_data,0);

			ptr_xweightl+=16;
			ptr_xweightr+=16;
			data+=16;
			vrd_data+=indx[l];
		}
		data = src + src_step * (coordy[i] + src_height);
		num1 = dnum2;
		for(l = 0; num1 < dst_w; num1++)
		{
			int sum = data[coordx[num1]] * x_weightl[coordx[num1]] + data[coordx1[num1]] * x_weightr[coordx[num1]];
			vrd_data[l++] = sum >> 4;
		}
	}
}
static void mxuClip(const unsigned char* src, unsigned char* dst, int src_w, int src_h, int src_step, int src_height)
{
	int i,j;
	unsigned char *dst_data;
	const unsigned char *src_data;

	int loop = src_w >> 6;
	int loop1 = src_w >> 4;
	v16u8 VD_src1,VD_src2,VD_src3,VD_src4;

	int S_loop = src_w - (loop1 << 4);
	for(j = 0; j < src_h; j++)
	{
		src_data = src + j*src_step;
		dst_data = dst + j*src_w;
		for(i = 0; i < loop; i+=4)
		{
			LU1Q(VD_src1, src_data, 0);
			LU1Q(VD_src2, src_data, 16);
			LU1Q(VD_src3, src_data, 32);
			LU1Q(VD_src4, src_data, 48);

			SU1Q(VD_src1, dst_data, 0);
			SU1Q(VD_src2, dst_data, 16);
			SU1Q(VD_src3, dst_data, 32);
			SU1Q(VD_src4, dst_data, 48);
			src_data += 64;
			dst_data += 64;
		}
		for(;i < loop1; i++)
		{
			LU1Q(VD_src1, src_data, 0);
			SU1Q(VD_src1, dst_data, 0);
			src_data += 16;
			dst_data += 16;
		}
		for(i = 0; i < S_loop; i++)
			dst_data[i] = src_data[i];
	}

	src += (src_height*src_step);
	dst += (src_h * src_w);
	src_h >>= 1;
	for(j = 0; j < src_h; j++)
	{
		src_data = src + j*src_step;
		dst_data = dst + j*src_w;
		for(i = 0; i < loop; i+=4)
		{
			LU1Q(VD_src1, src_data, 0);
			LU1Q(VD_src2, src_data, 16);
			LU1Q(VD_src3, src_data, 32);
			LU1Q(VD_src4, src_data, 48);

			SU1Q(VD_src1, dst_data, 0);
			SU1Q(VD_src2, dst_data, 16);
			SU1Q(VD_src3, dst_data, 32);
			SU1Q(VD_src4, dst_data, 48);
			src_data += 64;
			dst_data += 64;
		}
		for(;i < loop1; i++)
		{
			LU1Q(VD_src1, src_data, 0);
			SU1Q(VD_src1, dst_data, 0);
			src_data += 16;
			dst_data += 16;
		}
		for(i = 0; i < S_loop; i++)
			dst_data[i] = src_data[i];
	}
}

void c_resize_simd(uint8_t* src, uint8_t* dst, int src_w, int src_h, int dst_w, int dst_h, bool is_clip, int clip_offset, int clip_w, int clip_h, c_csp_t format, uint16_t *resize_buf)
{
	//int64_t i_start = c_mdate();
	int src_step = src_w;
    int src_height = src_h - (int)(clip_offset/(src_step << 1));

	if (is_clip) {
		src = src + clip_offset;
		src_w = clip_w;
		src_h = clip_h;
	}
	if(src_w == dst_w && src_h == dst_h) {
		mxuClip(src, dst, src_w, src_h, src_step, src_height);
	} else if ((src_w == 1280) && (dst_w == 1280) && (src_h == 720) && (dst_h == 960)) {
		c_resize_simd_nv12_up_h_720_960p_onlynear(src, dst, src_w, src_h, dst_w, dst_h, src_step, src_height, resize_buf);
	} else if ((src_w == 1280) && (dst_w == 720) && (src_h == 720) && (dst_h == 576)) {
		c_resize_simd_nv12_720_to_D1_near_down(src, dst, src_w, src_h, dst_w, dst_h, src_step, src_height, resize_buf);
	} else if (src_w <= dst_w) {
		c_resize_simd_nv12_up(src, dst, src_w, src_h, dst_w, dst_h, src_step, src_height, resize_buf);
	} else {
		c_resize_simd_nv12_down(src, dst, src_w, src_h, dst_w, dst_h, src_step, src_height, resize_buf);
	}
	//c_log(C_LOG_INFO, "%s cost time=%lld,src_w=%d, src_h=%d, dst_w=%d, dst_h=%d, src_step=%d, src_height=%d\n", __func__, c_mdate() - i_start, src_w, src_h, dst_w, dst_h, src_step, src_height);
	//IMP_LOG_DBG("RESIZE", "%s cost time=%lld,src_w=%d, src_h=%d, dst_w=%d, dst_h=%d, src_step=%d, src_height=%d\n", __func__, c_mdate() - i_start, src_w, src_h, dst_w, dst_h, src_step, src_height);
}
